package cn.bughub.service.impl;

import cn.bughub.mapper.DataSourceMapper;
import cn.bughub.model.entity.DataSourcesEntity;
import cn.bughub.model.vo.datasource.AddDataSourceRequestVo;
import cn.bughub.service.DataSourceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 *数据源业务实现层
 *
 * @author zwj
 * @date 2024-09-25
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DataSourceServiceImpl implements DataSourceService {
    
    private final DataSourceMapper dataSourceMapper;
    
    /**
     * 添加数据源
     *
     * @param addDataSourceRequestVo 加数据源请求实体类
     * @return {@link Long }
     */
    @Override
    public Long addDataSource(AddDataSourceRequestVo addDataSourceRequestVo) {
        
        DataSourcesEntity dataSourcesEntity = new DataSourcesEntity();
        BeanUtils.copyProperties(addDataSourceRequestVo, dataSourcesEntity);
        dataSourceMapper.insert(dataSourcesEntity);
        return dataSourcesEntity.getSourceId();
    }
}
